package com.zed;

import org.apache.axis2.AxisFault;
import org.apache.axis2.addressing.EndpointReference;
import org.apache.axis2.client.Options;
import org.apache.axis2.kernel.http.HTTPConstants;
import org.apache.axis2.rpc.client.RPCServiceClient;

import javax.xml.namespace.QName;
import java.util.Date;

public class Axis2Util {
    public static String invoke(String address, String namespaceURI, String localPart, Object[] argArr) throws AxisFault {
        RPCServiceClient serviceClient = new RPCServiceClient();
        Options options = serviceClient.getOptions();
        options.setTo(new EndpointReference(address));
        options.setManageSession(true);
        options.setProperty(HTTPConstants.REUSE_HTTP_CLIENT, true);

        QName opAddEntry = new QName(namespaceURI, localPart);
        Object[] objects = serviceClient.invokeBlocking(opAddEntry, argArr, new Class[]{String.class});
        serviceClient.cleanupTransport();
        return String.valueOf(objects[0]);
    }

    public static void main(String[] args) throws AxisFault {
        String address = "http://192.168.88.11:8080/axis2/services/LogService/acceptLogs";
//        String address = "http://10.35.50.231/axis2/services/LogService/acceptLogs";

        String sendID = "320281" + String.format("%1$tY%1$tm%1$td%1$tH%1$tM%1$tS%1$tL%1$tN", new Date());
        System.out.println(sendID);

        String xmlStr = "<?xml version=\"1.0\" encoding=\"UTF-8\"?><Aspt><Version>1.0</Version><RegID>JY320281100501</RegID><Logs><Log><Num_ID>JY320281100501320281202308085</Num_ID><User_ID>320281199604221512</User_ID><Organization>华士派出所</Organization><Organization_ID>32028179</Organization_ID><User_Name>管理员测试</User_Name><Terminal_ID>0.0.0.0</Terminal_ID><Operate_Time>20230808152025</Operate_Time><Operate_Result>1</Operate_Result><Operate_Name>测试查询1</Operate_Name><Operate_Type>1</Operate_Type><Error_Code></Error_Code><Operate_Condition><![CDATA[测试='测试测试测试测试测试测试测试测试测试测试']]></Operate_Condition></Log></Logs></Aspt>";
        System.out.println(xmlStr);

        Object[] argArr = new Object[]{"JY320281100501", sendID, "1", xmlStr};
        String ret = invoke(address, "http://service.web.kaituo.org", "acceptLogs", argArr);
        System.out.println(ret);
    }

}
